/**
 * This provides interface to the localStorage and sessionStorage.
 * @module
 */

/* -------------------------------------------
 *              sessionStorage
 * -------------------------------------------*/

/**
 * Save data in session storage
 * @param {string} key - the key for data
 * @param {object} value - any JS native data type
 */
export function saveToSession(key, value) {
    sessionStorage.setItem(key, JSON.stringify(value));
  }
  
  /**
   * Get data from session storage
   * @param {string} key - the key for data
   * @return {object} value - any data stored in cache
   */
  export function getFromSession(key) {
    return JSON.parse(sessionStorage.getItem(key));
  }
  
  /**
   * Remove data from session storage
   * @param {string} key - the key for data
   */
  export function removeFromSession(key) {
    return sessionStorage.removeItem(key);
  }
  
  /**
   * Clear session storage
   */
  export function clearSession() {
    return sessionStorage.clear();
  }
  
  /* -------------------------------------------
   *                LocalStorage
   * -------------------------------------------*/
  
  /**
   * Save data in local cache
   * @param {string} key - the key for data
   * @param {object} value - any data type
   */
  export function saveToStorage(key, value) {
    localStorage.setItem(key, JSON.stringify(value));
  }
  
  /**
   * Get data from local cache
   * @param {string} key - the key for data
   * @return {object} value - any data stored in cache
   */
  export function getFromStorage(key) {
    return JSON.parse(localStorage.getItem(key));
  }
  
  /**
   * Remove data from session storage
   * @param {string} key - the key for data
   */
  export function removeFromStorage(key) {
    return localStorage.removeItem(key);
  }
  
  /**
   * Clear session storage
   */
  export function clearStorage() {
    return localStorage.clear();
  }
  